package com.huajin.codetest.base;

public class StringBufferTest {
	
	public static String join1(String element1, String element2) {
		StringBuffer sb = new StringBuffer();
		sb.append(element1);
		sb.append(element2);
		return sb.toString();
	}
	
	public String join2(String element1, String element2) {
		StringBuffer sb = new StringBuffer();
		sb.append(element1);
		sb.append(element2);
		return sb.toString();
	}
	
	public String join3(String element1, String element2) {
		StringBuilder sb = new StringBuilder();
		sb.append(element1);
		sb.append(element2);
		return sb.toString();
	}
	
	public String method() {
	    StringBuffer sb = new StringBuffer();
	    for (int i = 0; i < 10; i++) {
	        sb.append(i);
	    }
	    return sb.toString();
	}
	
	public static void main(String[] args) {
		StringBufferTest test = new StringBufferTest();
		String a = "n";
		long start = System.currentTimeMillis();
		for (int i = 0; i < 1000000; i++) {
			test.join2(a, a);
		}
		long timeCost = System.currentTimeMillis() - start;
        System.out.println("createStringBuffer:" + timeCost + " ms");
//        long start1 = System.currentTimeMillis();
//		for (int i = 0; i < 1000000; i++) {
//			test.join3(a, a);
//		}
//		long timeCost1 = System.currentTimeMillis() - start1;
//        System.out.println("createStringBuilder:" + timeCost1 + " ms");
	}

}
